// router
import Vue from 'vue'
import VueRouter from 'vue-router'
import home from './pages/home'
import detail from './pages/detail'
import index from './index'
import store from './store/index'
require ("select2/dist/js/select2.min.js");
require ("select2/dist/css/select2.min.css");
Vue.use(VueRouter);

const routes = [
  { path: '/',
    name:"home",
    component: home
  },
  { path: '/home',
    name:"home",
    component: home
  },
  { path: '/detail',
    name:"detail",
    component: detail
  }
]

// 3. 创建 router 实例，然后传 `routes` 配置
const router = new VueRouter({
  // mode: 'history',
  routes
})
window.$store = store;
// 4. 创建和挂载根实例。
//select2指令
Vue.directive('select2', {
  inserted: function (el, binding, vnode) {
    let options = binding.value || {};
    $(el).select2(options).on("select2:select", (e) => {
      // v-model looks for
      //  - an event named "change"
      //  - a value with property path "$event.target.value"
      el.dispatchEvent(new Event('change', { target: e.target }));
    });
  },
  update: function(el, binding, vnode) {
    $(el).trigger("change");
  }
});

const app = new Vue({
  store,
  router,
  render: h => h(index)
}).$mount('#app');
var { query, path } = app.$route;
